package com.yf.dmp.controller;

import com.alibaba.fastjson.JSON;
import com.yf.dmp.bean.QueryInfo;
import com.yf.dmp.bean.TableMap;
import com.yf.dmp.service.TableMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@CrossOrigin
public class TableMapController {
    @Autowired
    TableMapService tmService;

    @RequestMapping("/tablemap")
    public String getSystemList(QueryInfo queryInfo) {
        return  tmService.getTableMap(queryInfo);
    }

    @RequestMapping("/addtablemap")
    public String addUser(@RequestBody TableMap tableMap){
        int i = tmService.addTableMap (tableMap);
        return   i>0?"Success":"Error";
    }

    @RequestMapping("/deletetablemap")
    public String deleteTableMapById(int id) {
        int i = tmService.deleteTableMapById(id);
        System.out.println(id + "用户被删除");
        return i > 0 ? "Success" : "Error";
    }

    @RequestMapping("/getupdatetablemap")
    public String getUpdateTableMap(int id){
        System.out.println(id+"用户进入修改");
        TableMap tm = tmService.getUpdateTableMap(id);
        String jsonstr = JSON.toJSONString(tm);
        return jsonstr;
    }

    @RequestMapping("/updatetablemap")
    public String updateTableMap(@RequestBody TableMap tm){
        int i = tmService.updateTableMap (tm);
        return   i>0?"Success":"Error";
    }
}
